package com.live.stamp.web.user.controller;

import com.live.stamp.base.token.TokenAuth;
import com.live.stamp.base.validation.ParamHandlerManager;
import com.live.stamp.base.validation.ValidationEnum;
import com.live.stamp.global.commonenum.HandleTypeEnum;
import com.live.stamp.global.commonenum.ListTypeEnum;
import com.live.stamp.global.commonenum.SmsTemplateEnum;
import com.live.stamp.web.sms.service.model.SmsModel;
import com.live.stamp.web.user.service.UserService;
import com.live.stamp.web.user.vo.TUserVo;
import org.springframework.boot.container.core.common.BusinessException;
import org.springframework.boot.container.core.common.ServerResponse;
import org.springframework.boot.container.core.controller.BaseRestController;
import org.springframework.boot.container.core.log.ZKLogger;
import org.springframework.boot.container.core.log.ZKLoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户restController
 * @author cwd E-mail: wendong.cao@jsxfedu.com
 * @version 1
 * @date 2018/3/14 17:14
 */
@RestController
@RequestMapping("/user")
public class UserRestController extends BaseRestController {
    private static final ZKLogger logger = ZKLoggerFactory.getLogger(UserRestController.class);

    @Resource
    private UserService userService;

    /**
     * @api {post} /user/login 用户登录
     * @apiSampleRequest /user/login
     * @apiName login
     * @apiGroup user
     * @apiDescription 用户登录
     * @apiParam {String} phone 手机号
     * @apiParam {String} password 密码
     * @apiParam {String} [userName] 用户名
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": null,
            "data": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1MmRlYzkxYzE2MmJkYWY3ZmMxN0RFNTA2QTVBOEYzOEVDM0I5MDQwQjUyMUNEODM3RjEiLCJleHAiOjEwOTUyMzYwMDkwMX0.3UFGDZmh4whICm-JEUUwIZUhIzfzk95YkC8BPlU--bTiu_xov8xLrutfyzMreWGd5WNZ--fha0WsL6v9Gngt4g"
        }
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ServerResponse login(TUserVo tUserVo) {
        logger.info("enter login controller tUserVo:{}", tUserVo);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(userService.login(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/register 用户注册
     * @apiSampleRequest /user/register
     * @apiName register
     * @apiGroup user
     * @apiDescription 用户注册
     * @apiParam {String} phone         --手机号
     * @apiParam {String} password      --密码
     * @apiParam {String} userName      --用户名
     * @apiParam {String} photoUrl      --头像地址
     * @apiParam {String} verCode       --验证码
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": null,
            "data": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1MmRlYzkxYzE2MmJkYWY3ZmMxN0RFNTA2QTVBOEYzOEVDM0I5MDQwQjUyMUNEODM3RjEiLCJleHAiOjEwOTUyMzYwMDgxOH0.eFrH5Z3B4LupVCN-hfCCH4jLvCUU90UtiajCKCEiyjgzdBvYS9HjwPQibeDoJrmEqD0tFoAm8lG_3jeEOIbYTw"
        }
     */
    @RequestMapping("/register")
    public ServerResponse register(TUserVo tUserVo) {
        logger.info("enter register controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            ParamHandlerManager.getHeadHandle().handleMessage("phone", tUserVo.getPhone(), ValidationEnum.BLANK)
                    .handleMessage("password", tUserVo.getPassword(), ValidationEnum.BLANK)
                    .handleMessage("verCode", tUserVo.getVerCode(), ValidationEnum.BLANK);

            serverResponse.setData(userService.register(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/sendVerCode 发送验证码
     * @apiSampleRequest /user/sendVerCode
     * @apiName sendVerCode
     * @apiGroup user
     * @apiDescription 发送验证码
     * @apiParam {String} phone 手机号
     * @apiParam {String} type  类型：ZC:注册， XG：重置密码
     * @apiParamExample {json} 参数示例:
     * {
     *  phone:'1888888888'
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": null,
            "data": "6282"
        }
     */
    @RequestMapping("/sendVerCode")
    public ServerResponse sendVerCode(String phone, String type) {
        logger.info("enter sendVerCode controller phone:{}", phone);
        ServerResponse serverResponse = new ServerResponse();
        try{
            ParamHandlerManager.getHeadHandle().handleMessage("phone", phone, ValidationEnum.BLANK)
                    .handleMessage("phone", phone, ValidationEnum.PHONE)
                    .handleMessage("type", type, ValidationEnum.BLANK);

            SmsModel smsModel = new SmsModel();
            smsModel.setPhone(phone);
            smsModel.setSmsTemplate(SmsTemplateEnum.valueOf(type));
            userService.sendVerCode(smsModel);

            serverResponse.setData("");
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/resetPassword 重置密码
     * @apiSampleRequest /user/resetPassword
     * @apiName resetPassword
     * @apiGroup user
     * @apiDescription 重置密码
     * @apiParam {String} phone 手机号
     * @apiParam {String} password 新密码
     * @apiParam {String} verCode  验证码
     * @apiParamExample {json} 参数示例:
     * {
     *  phone:'1888888888',
     *  password:'1888888888',
     *  verCode:'2456'
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": null,
            "data": null
        }
     */
    @RequestMapping("/resetPassword")
    public ServerResponse resetPassword(TUserVo tUserVo) {
        logger.info("enter resetPassword controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{

            ParamHandlerManager.getHeadHandle().handleMessage("phone", tUserVo.getPhone(), ValidationEnum.BLANK)
                    .handleMessage("password", tUserVo.getPassword(), ValidationEnum.BLANK)
                    .handleMessage("verCode", tUserVo.getVerCode(), ValidationEnum.BLANK);

            serverResponse.setData(userService.resetPassword(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }


    /**
     * @api {post} /user/getFriendList 好友列表
     * @apiSampleRequest /user/getFriendList
     * @apiName getFriendList
     * @apiGroup user
     * @apiDescription 好友列表
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
        "code": 200,
        "msg": null,
        "data": [
            {
                "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
                "userName": "cwd",                                                      --用户名
                "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
                "phone": "18888888888",                                                 --电话
                "photoUrl": "test",                                                     --头像
                "signature": "test",                                                    --签名
                "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
                "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
                "createTime": "2018-04-13T06:26:58.000+0000",
                "friendCount": 0,
                "attentionCount": 0,
                "sex": null,
                "profession": null,
                "likeLocation": null,
                "likeLable": null,
                "state": "1",
                "reqTime": null                                                         --请求时间
            }
            ]
        }
     */
    @RequestMapping("/getFriendList")
    @TokenAuth
    public ServerResponse getFriendList(TUserVo tUserVo) {
        logger.info("enter getFriendList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{

            tUserVo.setState("1");   //状态：0 删除、1 已添加 、2 请求、3 已拒绝
            tUserVo.setListType(ListTypeEnum.FRIEND.toString());
            serverResponse.setData(userService.amityList(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/getAttentList 关注列表
     * @apiSampleRequest /user/getAttentList
     * @apiName getAttentList
     * @apiGroup user
     * @apiDescription 关注列表
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
        "code": 200,
        "msg": null,
        "data": [
            {
                "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
                "userName": "cwd",                                                      --用户名
                "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
                "phone": "18888888888",                                                 --电话
                "photoUrl": "test",                                                     --头像
                "signature": "test",                                                    --签名
                "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
                "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
                "createTime": "2018-04-13T06:26:58.000+0000",
                "friendCount": 0,
                "attentionCount": 0,
                "sex": null,
                "profession": null,
                "likeLocation": null,
                "likeLable": null,
                "state": "1",
                "reqTime": null                                                         --请求时间
            }
            ]
        }
     */
    @RequestMapping("/getAttentList")
    @TokenAuth
    public ServerResponse getAttentList(TUserVo tUserVo) {
        logger.info("enter getAttentList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setListType(ListTypeEnum.ATTENT.toString());
            serverResponse.setData(userService.amityList(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/getFansList 粉丝列表
     * @apiSampleRequest /user/getFansList
     * @apiName getFansList
     * @apiGroup user
     * @apiDescription 关注列表
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
        {
            "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
            "userName": "cwd",                                                      --用户名
            "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
            "phone": "18888888888",                                                 --电话
            "photoUrl": "test",                                                     --头像
            "signature": "test",                                                    --签名
            "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
            "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
            "createTime": "2018-04-13T06:26:58.000+0000",
            "friendCount": 0,
            "attentionCount": 0,
            "sex": null,
            "profession": null,
            "likeLocation": null,
            "likeLable": null,
            "state": "1",
            "reqTime": null                                                         --请求时间
        }
    ]
    }
     */
    @RequestMapping("/getFansList")
    @TokenAuth
    public ServerResponse getFansList(TUserVo tUserVo) {
        logger.info("enter getAttentList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setListType(ListTypeEnum.FANS.toString());
            serverResponse.setData(userService.amityList(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/getReqFriendList 好友申请列表
     * @apiSampleRequest /user/getReqFriendList
     * @apiName getReqFriendList
     * @apiGroup user
     * @apiDescription 好友申请列表
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
        "code": 200,
        "msg": null,
        "data": [
            {
                "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
                "userName": "cwd",                                                      --用户名
                "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
                "phone": "18888888888",                                                 --电话
                "photoUrl": "test",                                                     --头像
                "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
                "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
                "createTime": "2018-04-13T06:26:58.000+0000",
                "friendCount": 0,
                "attentionCount": 0,
                "sex": null,
                "profession": null,
                "likeLocation": null,
                "likeLable": null,
                "state": "1" ,
                "reqTime": null,                                                        --请求时间
                "greet": "你好啊,加个好友来聊啊",                                        --打招呼
                "reqId ": "请求id"                                                      --打招呼
            }
            ]
        }
     */
    @RequestMapping("/getReqFriendList")
    @TokenAuth
    public ServerResponse getReqFriendList(TUserVo tUserVo) {
        logger.info("enter getReqFriendList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{

            tUserVo.setState("2");   //状态：0 删除、1 已添加 、2 请求、3 已拒绝
            tUserVo.setListType(ListTypeEnum.FRIEND.toString());
            serverResponse.setData(userService.amityList(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/reqAddFriend  申请添加好友
     * @apiSampleRequest /user/reqAddFriend
     * @apiName reqAddFriend
     * @apiGroup user
     * @apiDescription 申请添加好友
     * @apiParam {String} userId        申请用户id
     * @apiParam {String} greet         打招呼内容
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": {}
    }
     */
    @RequestMapping("/reqAddFriend")
    @TokenAuth
    public ServerResponse reqAddFriend(TUserVo tUserVo) {
        logger.info("enter getReqFriendList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(userService.reqAddFriend(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/shieldUser  屏蔽用户
     * @apiSampleRequest /user/shieldUser
     * @apiName shieldUser
     * @apiGroup user
     * @apiDescription 屏蔽用户
     * @apiParam {String} userId        屏蔽用户id
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": {}
    }
     */
    @RequestMapping("/shieldUser")
    @TokenAuth
    public ServerResponse shieldUser(TUserVo tUserVo) {
        logger.info("enter shieldUser controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            ParamHandlerManager.getHeadHandle().handleMessage("userId", tUserVo.getUserId(), ValidationEnum.BLANK);

            serverResponse.setData(userService.shieldUser(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/cancelShieldUser  取消屏蔽用户
     * @apiSampleRequest /user/cancelShieldUser
     * @apiName cancelShieldUser
     * @apiGroup user
     * @apiDescription 取消屏蔽用户
     * @apiParam {String} userId        取消屏蔽用户
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": {}
    }
     */
    @RequestMapping("/cancelShieldUser")
    @TokenAuth
    public ServerResponse cancelShieldUser(TUserVo tUserVo) {
        logger.info("enter cancelShieldUser controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            ParamHandlerManager.getHeadHandle().handleMessage("userId", tUserVo.getUserId(), ValidationEnum.BLANK);
            serverResponse.setData(userService.cancelShieldUser(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/reqAgreeFriend  同意添加好友
     * @apiSampleRequest /user/reqAgreeFriend
     * @apiName reqAgreeFriend
     * @apiGroup user
     * @apiDescription 同意添加好友
     * @apiParam {String} reqId        申请用户id
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
    {
    }
    ]
    }
     */
    @RequestMapping("/reqAgreeFriend")
    @TokenAuth
    public ServerResponse reqAgreeFriend(TUserVo tUserVo) {
        logger.info("enter reqAgreeFriend controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setHandleType(HandleTypeEnum.TY.toString());
            serverResponse.setData(userService.handleReqFriend(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/deleteFriend  删除好友
     * @apiSampleRequest /user/deleteFriend
     * @apiName deleteFriend
     * @apiGroup user
     * @apiDescription 删除好友
     * @apiParam {String} userId        删除好友id
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
    {
    }
    ]
    }
     */
    @RequestMapping("/deleteFriend")
    @TokenAuth
    public ServerResponse deleteFriend(TUserVo tUserVo) {
        logger.info("enter reqAgreeFriend controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            ParamHandlerManager.getHeadHandle().handleMessage("userId", tUserVo.getUserId(), ValidationEnum.BLANK);

            serverResponse.setData(userService.deleteFriend(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/reqRefuseFriend  拒绝添加好友
     * @apiSampleRequest /user/reqRefuseFriend
     * @apiName reqRefuseFriend
     * @apiGroup user
     * @apiDescription 拒绝添加好友
     * @apiParam {String} reqId        申请用户id
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
    {
    }
    ]
    }
     */
    @RequestMapping("/reqRefuseFriend")
    @TokenAuth
    public ServerResponse reqRefuseFriend(TUserVo tUserVo) {
        logger.info("enter reqRefuseFriend controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setHandleType(HandleTypeEnum.JJ.toString());
            serverResponse.setData(userService.handleReqFriend(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/addAttention  添加关注
     * @apiSampleRequest /user/addAttention
     * @apiName addAttention
     * @apiGroup user
     * @apiDescription 添加关注
     * @apiParam {String} userId        关注用户id
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
    {
    }
    ]
    }
     */
    @RequestMapping("/addAttention")
    @TokenAuth
    public ServerResponse addAttention(TUserVo tUserVo) {
        logger.info("enter addAttention controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setHandleType(HandleTypeEnum.GZ.toString());
            serverResponse.setData(userService.handleAttention(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/cancelAttention  取消关注
     * @apiSampleRequest /user/cancelAttention
     * @apiName cancelAttention
     * @apiGroup user
     * @apiDescription 添加关注
     * @apiParam {String} userId        关注用户id
     * @apiParam {String} token        token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
    {
    }
    ]
    }
     */
    @RequestMapping("/cancelAttention")
    @TokenAuth
    public ServerResponse cancelAttention(TUserVo tUserVo) {
        logger.info("enter cancelAttention controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{
            tUserVo.setHandleType(HandleTypeEnum.QXGZ.toString());
            serverResponse.setData(userService.handleAttention(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/getUserInfo  获取用户信息
     * @apiSampleRequest /user/getUserInfo
     * @apiName getUserInfo
     * @apiGroup user
     * @apiDescription 获取用户信息
     * @apiParam {String} [id]        id：用户id
     * @apiParam {String} token       token：如果查询登录用户信息只需传token参数
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
        "code": 200,
        "msg": null,
        "data":
            {
                "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
                "userName": "cwd",                                                      --用户名
                "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
                "phone": "18888888888",                                                 --电话
                "photoUrl": "test",                                                     --头像
                "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
                "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
                "createTime": "2018-04-13T06:26:58.000+0000",
                "friendCount": 0,                                                       --好友数
                "attentionCount": 0,                                                    --关注数量
                "sex": null,                                                            --性别：1 男，2女
                "profession": null,                                                     --职业
                "likeLocation": null,                                                   --常到地址
                "likeLable": null,                                                      --常用标签
                "signature": null,                                                      --签名
                "isFriend": 1,                                          --是否为好友 1：是， 0：否
                "isAttent": 1,                                          --是否已关注 1：是， 0：否
                "isShield": 1,                                          --是否已屏蔽 1：是， 0：否
                "state": "1" ,
            }
        }
     */
    @RequestMapping("/getUserInfo")
    @TokenAuth
    public ServerResponse getUserInfo(TUserVo tUserVo) {
        ServerResponse serverResponse = new ServerResponse();
        try{
            serverResponse.setData(userService.getUser(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/updateUserInfo  更新用户信息
     * @apiSampleRequest /user/updateUserInfo
     * @apiName updateUserInfo
     * @apiGroup user
     * @apiDescription 更新用户信息
     * @apiParam {String} token             --token
     * @apiParam {String} userName          --用户名
     * @apiParam {String} photoUrl          --头像地址
     * @apiParam {String} sex               --性别：1 男，2女
     * @apiParam {String} profession        --职业
     * @apiParam {String} signature         --签名
     * @apiParam {String} likeLocation      --常到地址
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data":
    {
    }
    }
     */
    @RequestMapping("/updateUserInfo")
    @TokenAuth
    public ServerResponse updateUserInfo(TUserVo tUserVo) {
        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(userService.updateUserInfo(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /user/queryUserList 搜索好友列表
     * @apiSampleRequest /user/queryUserList
     * @apiName queryUserList
     * @apiGroup user
     * @apiDescription 好友申请列表
     * @apiParam {String} key      好友名称或手机号
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": null,
    "data": [
        {
            "id": "52dec91c162bdaf7fc17DE506A5A8F38EC3B9040B521CD837F1",            --用户id
            "userName": "cwd",                                                      --用户名
            "password": "B2C0FA8BE8900AF7365852AC8AA4938D",
            "phone": "18888888888",                                                 --电话
            "photoUrl": "test",                                                     --头像
            "lastLookFriendTime": "2018-04-15T08:06:18.000+0000",
            "lastLookAttenTime": "2018-04-15T08:10:48.000+0000",
            "createTime": "2018-04-13T06:26:58.000+0000",
            "friendCount": 0,
            "attentionCount": 0,
            "sex": null,
            "profession": null,
            "likeLocation": null,
            "likeLable": null,
            "state": "1" ,
        }
        ]
    }
     */
    @RequestMapping("/queryUserList")
    public ServerResponse queryUserList(TUserVo tUserVo) {
        logger.info("enter getReqFriendList controller tUserVo:{}", tUserVo);
        ServerResponse serverResponse = new ServerResponse();

        try{

            serverResponse.setData(userService.queryUserList(tUserVo));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

}
